//
//  ZDBFeedbackInfoVC.m
//  ZDB
//
//  Created by Kk on 2020/3/30.
//  Copyright © 2020 ZDB. All rights reserved.
//

#import "ZDBFeedbackInfoVC.h"
#import "HUPhotoBrowser.h"

@interface ZDBFeedbackInfoVC ()
@property(strong,nonatomic)UIImageView * imageVIEW;
@end

@implementation ZDBFeedbackInfoVC

- (void)viewDidLoad {
    [super viewDidLoad];
    KViewRadius(_userIcon, _userIcon.height/2);
    KViewRadius(_severIcon, _severIcon.height/2);
    NSDictionary * userDic = [[DJLoginHelper sharedInstance] cj_UserDicc];
    _userName.text = userDic[@"userName"];
    [self.userIcon sd_setImageWithURL:[NSURL URLWithString:[userDic jsonString:@"headImage"]] placeholderImage:PlaceHolderImage];
    NSString * conten = _model.content;
    NSData *data = [conten dataUsingEncoding:NSUnicodeStringEncoding];
    NSDictionary *options = @{NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType};
    NSMutableAttributedString *attr = [[NSMutableAttributedString alloc] initWithData:data options:options documentAttributes:nil error:nil];
    [attr addAttribute:NSFontAttributeName value:AutoFont(12) range:NSMakeRange(0, attr.length)];
    CGSize attSize = [attr boundingRectWithSize:CGSizeMake(UIScreenWidth-30, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading context:nil].size;
    _contentLab.height = attSize.height;
    _headView_h.constant = 110-36 + attSize.height;
    _contentLab.text = conten;
    _lookBtn.hidden = YES;
    if (_model.feedbackImageList.count>0) {
        _lookBtn.hidden = NO;
    }
    _time.text = _model.createTime;
    _contentLab.text = _model.content;
    [_lookBtn add_BtnClickHandler:^(NSInteger tag) {
        [self lookImage];
    }];
    
    if (kStringIsEmpty(_model.replyContent)) {
        _serverView.hidden = YES;
    }else
    {
        NSString * serverConten = _model.replyContent;
        NSData *serverdata = [serverConten dataUsingEncoding:NSUnicodeStringEncoding];
        NSDictionary *serveroptions = @{NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType};
        NSMutableAttributedString *serverattr = [[NSMutableAttributedString alloc] initWithData:serverdata options:serveroptions documentAttributes:nil error:nil];
        [serverattr addAttribute:NSFontAttributeName value:AutoFont(12) range:NSMakeRange(0, serverattr.length)];
        CGSize serverattSize = [serverattr boundingRectWithSize:CGSizeMake(UIScreenWidth-30, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading context:nil].size;
        _serverContentLab.height = serverattSize.height;
        _severView_h.constant = 90-36 + serverattSize.height;
        _serverContentLab.text = serverConten;
        _serverTime.text = _model.replyTime;
    }
    
   
    _imageVIEW = [[UIImageView alloc] initWithFrame:self.lookBtn.frame];
    [self.view addSubview:_imageVIEW];
    
    
    
}
- (void)lookImage
{
    NSMutableArray * images = [NSMutableArray new];
    for (NSDictionary * dic in _model.feedbackImageList)
    {
        [images addObject:dic[@"url"]];
    }
    [HUPhotoBrowser showFromImageView:_imageVIEW withURLStrings:images atIndex:0];
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
